home *** CD-ROM | disk | FTP | other *** search
- /*
- NetWare Alloy Archive Utility (Front-End Procedures)
- V4.42 02/04/84 by Mark Hurst
-
- For use with NetWare V4.n Systems
-
- Copyright (C) 1983, 1984 Novell, Inc.
- */
-
- #include "ctype.h"
- #include "stdio.h"
-
-
- #define LOCALBIT 0x80
- #define PERMNET 0x01
- #define TEMPNET 0x02
- #define NETBITS 0x03
-
- #define READBIT 0x01
- #define WRITEBIT 0x02
- #define OPENBIT 0x04
- #define CREATEBIT 0x08
- #define DELETEBIT 0x10
- #define OWNEDBIT 0x20
- #define SEARCHBIT 0x40
- #define MODIFYBIT 0x80
-
- /* NOTE: the Archive bit was 0x80 on ShareNet V3.12. Has now changed: */
- #define BACKUPBIT 0x20
-
- static char author[] =
- "Author: Mark Hurst of SuperSet Software Corp. Copyright (C) 1984";
-
- unsigned DOS11, DOS20;
-
- struct volstruct {
- unsigned SecPerBlock;
- unsigned TotalBlocks;
- unsigned UnusedBlocks;
- unsigned TotalDir;
- unsigned UnusedDir;
- char vol_name[16];
- unsigned remove;
- } volinfo2;
-
-
- #define VARPATH '^' - 'A'
-
- #define TRUE 1
- #define FALSE 0
-
- #define MAXVOLUMES 16
- #define MAXSPECS 100
-
- #define ALLMODE 1
- #define MODMODE 2
- #define SELMODE 3
-
- int printlog, spool;
-
- char actarget[20];
-
- int startup;
-
- extern unsigned fileswritten;
-
- int system, continuous, finclude, fexclude;
- char *speclist[MAXSPECS];
- int speccount;
-
- int savestate, dontask;
-
- int numberqualified, numberout;
- char *calloc(), *malloc();
-
- unsigned known, firsttypecheck, unusabledisk;
-
- extern struct dirret {
- int maxlen;
- char subname[16];
- char createtime[4];
- char user_unique[4];
- char mask;
- char pad_junk;
- int subnum;
- } subinfo;
-
- typedef struct dosfcb {
- char drive;
- char fname[8];
- char fext[3];
- unsigned curblk;
- unsigned recsize;
- long size;
- unsigned date;
- char reserved[10];
- char relrec;
- char record[4];
- } FCB;
-
- typedef struct exdirfcb {
- char dummy;
- char exset;
- char res[5];
- char flags;
- char drive;
- char fname[8];
- char fext[3];
- char gap[17];
- char size[4];
- } ExDirFCB;
-
- typedef struct exdosfcb {
- char dummy;
- char exset;
- char res[5];
- char flags;
- char drive;
- char fname[8];
- char fext[3];
- unsigned curblk;
- unsigned recsize;
- long size;
- unsigned date;
- char reserved[10];
- char relrec;
- char record[4];
- } ExFCB;
-
- int mode, bdrive, firstcopy;
-
- char pathstring[256];
- char privmask;
-
- int listcount;
- typedef struct liststruct {
- struct liststruct *link;
- char name[12]; /* 1 too big for even allocation */
- char marked;
- char flags;
- long size; /* size of file in bytes */
- unsigned units; /* size of file in allocation units */
- } LISTNODE;
-
- #define LISTSIZE 250
- LISTNODE *list[LISTSIZE], *curnode;
-
- int saverights;
- int logexists; /* flag; TRUE means there is an existing log file */
- extern FCB logfcb;
- extern int BrkFlag;
-
- int imin();
- unsigned umin();
- long lmin();
-
- abort()
- {
- cprintf("\r\n\7Archive session terminated.\r\n");
- if (printlog) {
- prnline();
- printstr("ARCHIVE SESSION CANCELLED\r\n");
- prnline();
- }
- myexit(0);
- }
-
- checkbreak()
- {
- char ch;
- ChkKey();
- if (BrkFlag) {
- cprintf("\r\n\7");
- if (yes("Cancel Archive session? (Y/N) ")) {
- abort();
- }
- BrkFlag = 0;
- }
- }
-
- myexit(exitcode)
- int exitcode;
- {
- if (printlog) {
- printstr("\r\n\r\n");
- prnline();
- printstr("END OF ARCHIVE LOG REPORT\r\n");
- prnline();
- }
- modLST(1); /* restore LST: to local and signal spooler to print */
- rewindtape();
- exit(exitcode);
- }
-
- /* FATAL ERROR REPORTING ROUTINE */
- error(message)
- char *message;
- {
- cprintf("FATAL ERROR: %s\7\r\n", message);
- if (printlog) {
- prnline();
- printstr("FATAL ERROR: "); printstr(message); printstr("\r\n");
- prnline();
- }
- }
-
- extern char inline[];
-
-
- showsub (level)
- int level;
- {
- int i, spaces;
- char nextlevel[18];
-
- i = 1;
- while(getsubinfo(VARPATH, i) == 0) {
- /* got a subdirectory */
- i = subinfo.subnum + 1;
- subinfo.subname[15] = 0;
- pathmodset (VARPATH, VARPATH, subinfo.subname); /* drop to next sub level */
-
- /* BACKUP UP THIS PARTICULAR DIRECTORY */
- backupdir();
-
- /* BACKUP NEXT LAYER DOWN IN THE DIRECTORY HIERARCHY */
- showsub (level + 1);
- pathmodset (VARPATH, VARPATH, ".."); /*come back to my level*/
- }
- return (i-1);
- }
-
-
- showroot (line)
- char *line;
- {
- firstpath (line);
- if (startup) {
- setup();
- startup = FALSE;
- configlog();
- tapesetup();
- if (savestate) ssave ();
- }
-
- /* BACKUP UP THIS ROOT */
- backupdir();
-
- /* do subdirectories now */
- showsub (1);
- }
-
-
- setup()
- {
- privmask = READBIT | SEARCHBIT | OPENBIT | MODIFYBIT;
-
- if (dontask == FALSE) {
- if (!yes ("Do you want to save directory rights and trustee lists? (Y/N) "))
- saverights = FALSE;
- else saverights = TRUE;
- ssquery ();
- }
-
- if (yes(
- "Do you want the specified directories to be scanned w/out interruption? (Y/N) ")) {
- continuous = TRUE;
- mode = 0;
- cprintf("Select backup mode for ALL directories from following:\r\n");
- cprintf(" 1) Backup ALL qualified files in each directory\r\n");
- cprintf(" 2) Backup ONLY qualified files that have been modified since last backup\r\n");
- cprintf("\r\n");
- while (mode != ALLMODE && mode != MODMODE) {
- cprintf("Select Option: (1, 2) ");
- mode = getstr(inline, 1);
- if (mode == 0x03) abort();
- mode = mode - '0';
- cprintf("\r\n");
- }
- inexquery();
- }
- else continuous = FALSE;
- }
-
- backupdir()
- {
- checkbreak(); /* check for ^C or ^S as each directory is checked */
- getcurpath (VARPATH, pathstring);
- if (!checkrights(VARPATH, privmask)) {
- if (printlog) printstr("\r\n");
- lprint(pathstring);
- lprint("\r\n No backup privileges.\r\n");
- return;
- }
-
- /* INITIALIZE LIST POINTER ARRAY FOR LIST OF FILES TO BACKUP */
- setmem(list,LISTSIZE*2, 0);
- listcount = 0;
-
- /* DO BACKUP OF DIRECTORY */
- scandir();
- }
-
- static char *badnames[] = {"CON", "AUX", "COM1", "LPT1", "PRN", "NUL", 0};
-
- badname(f)
- ExDirFCB *f;
- {
- int i, j, match;
- char *s;
-
- i = 0;
- while (badnames[i]) {
- s = badnames[i++];
- match = TRUE;
- for (j=0; j < strlen(s) && match; j++) {
- if (s[j] != f->fname[j]) match = FALSE;
- }
- if (match) {
- if (f->fname[j] == 0x20) return (TRUE); /* BAD NAME */
- }
- }
- return (FALSE);
- }
-
- scandir()
- {
- ExFCB search, file;
- ExDirFCB *dfile;
- char ch;
- int ccode;
-
- setmem(&search, sizeof(ExFCB), 0);
- setmem(search.fname, 11, '?');
- search.drive = VARPATH + 1;
- search.exset = 0xFF;
- search.flags = 0x02 | 0x04; /* PULL IN HIDDEN AND SYS FILES ALSO */
- dfile = (ExDirFCB *)&file;
- setDTA(&dfile->exset);
-
- ccode = search1(&search.exset);
-
- if (printlog) printstr("\r\n");
- lprint(pathstring);
- lprint("\r\n");
-
- while (ccode == 0 && badname(dfile)) ccode = searchn(&search.exset);
- if (!saverights) {
- if (ccode) {
- lprint (" No files.\r\n");
- return;
- }
- }
-
- if (!continuous) {
- if (ccode) { /* no files */
- if (saverights) {
- cprintf (" There are no files in this directory.\r\n");
- if (!yes(
- " Do you still want to backup the directory rights and trustees? (Y/N) ")) {
- if (printlog) {
- printstr (
- " No files. User chose NOT to archive directory rights and trustees.\r\n");
- }
- return;
- }
- }
- }
- else {
- if (!yes(" Backup? (Y/N) ")) {
- if (printlog) printstr(saverights ?
- " User chose not to archive this directory's rights, trustees, or files.\r\n"
- : " User chose not to archive files from this directory.\r\n");
- return;
- }
- }
-
- if (ccode) goto doscan;
-
- mode = 0;
- cprintf("Select backup mode for this directory from following:\r\n");
- cprintf(
- " 1) Backup ALL qualified files in each directory\r\n");
- cprintf(
- " 2) Backup ONLY qualified files that have been modified since last backup\r\n");
- cprintf(
- " 3) Choose specific files during directory scan\r\n");
- cprintf("\r\n");
- while (mode < 1 || mode > 3) {
- cprintf("Select Option: (1-3) ");
- mode = getstr(inline, 1);
- if (mode == 0x03) abort();
- mode -= '0';
- cprintf("\r\n");
- }
- if (mode == ALLMODE || mode == MODMODE) inexquery();
- }
-
- doscan:
- /* DO DIRECTORY SCAN */
- numberout = numberqualified = 0;
- if (saverights) AddTrustFile ();
-
- while (ccode == 0) {
- if (!badname(dfile)) {
- if (verify(dfile)) addtolist(dfile);
- if (listcount == LISTSIZE) writelist();
- }
- setDTA(&dfile->exset);
- ccode = searchn(&search.exset);
- }
- writelist();
-
- if (mode == MODMODE && !numberqualified) {
- lprint(
- " No files in this directory changed since they were last archived.\r\n");
- }
-
- if (numberout == 0) {
- lprint(" No files archived from this directory.\r\n");
- }
- }
-
- verify(file)
- ExDirFCB *file;
- {
- int ret;
- ret = xverify(file);
- if (ret) numberqualified++;
- return (ret);
- }
-
- xverify(file)
- ExDirFCB *file;
- {
- char ch, f[15];
-
- /* CHECK FOR SPECIAL NETWORK FILES IN SUPERVISOR DIR AND IGNORE THEM */
- if (strcmp("SYS:SUPER", pathstring) == 0) {
- movmem(file->fname, f, 11);
- f[11] = 0;
- if (f[0] == 'S' && f[1] == 'P' && f[2] == 'L' &&
- f[5] == '$') return (FALSE);
- if (!strcmp(f, "NET$SPL QUE")) return (FALSE);
- if (!strcmp(f, "NET$MSG SYS")) return (FALSE);
- }
-
- switch(mode) {
- case SELMODE: /* Select files */
- cprintf(" ");
- showfile(&file->drive);
- if (yes(" Backup? (Y/N) ")) return (TRUE);
- else return (FALSE);
- break;
- case ALLMODE: /* Accept all files for backup */
- if (exclude(file->fname)) return (FALSE);
- if (!include(file->fname)) return (FALSE);
- return (TRUE);
- break;
- case MODMODE: /* Backup ONLY files changed since last backup */
- if (exclude(file->fname)) return (FALSE);
- if (!include(file->fname)) return (FALSE);
- if (file->gap[0] & BACKUPBIT) return (TRUE);
- else return (FALSE);
- break;
- }
- }
-
-
- addtolist(file)
- ExDirFCB *file;
- {
- curnode = (LISTNODE *) calloc(1, sizeof(LISTNODE));
- list[listcount++] = curnode;
- movmem(file->fname, curnode->name, 11);
- curnode->marked = 0; /* clear MARKED flag */
- curnode->flags = file->gap[0];
- movmem(file->size, &curnode->size, 4);
- curnode->units = 0;
- }
-
-
- _main(line)
- char *line;
- {
- int i;
-
- conupper (++line);
- compress(line);
- cpmoff(); /* set network interface shell to really close files */
- trapbreak(); /* stop DOS from aborting */
- main(line);
- cprintf("\r\nArchive Session Completed.");
- myexit(0);
- }
-
-
- main(l)
- char *l;
- {
- int ccode, root, colpos, len;
- char line[256], dd[4];
- unsigned OS, major, minor;
-
- DOS20 = DOS11 = FALSE;
-
- OS = GVersionNumber();
- major = (OS & 0x00FF);
- minor = (OS & 0xFF00) >> 8;
- if (major < 2) DOS11 = TRUE; /* REPRESENT DOS v1.1 */
- else if (major == 2) DOS20 = TRUE; /* REPRESENT DOS v2.0 */
-
-
- cprintf("TARCHIVE V4.42 BETA -- Archive to Alloy Tape \r\n");
- cprintf("Copyright (C) 1983, 1984 by Novell, Inc.\r\n\r\n");
-
- /* Save current mapping for fourth network drive to be used as temp */
- finclude, fexclude = FALSE; /* initialize no special inc or excs */
- printlog, spool = FALSE;
- firsttypecheck = TRUE;
- savestate = FALSE;
-
- setmem(&list[0], LISTSIZE * 2, 0x00); /* CLEAR LIST NODE POINTERS */
-
- startup = TRUE; /* this flag is checked in 'showroot()', where
- the user is asked all the set up questions
- only after we know his specified path domain is OK */
-
- if (!strcmp("SYSTEM", l)) {
- cprintf (
- "\r\nIMPORTANT: When making a system backup, it is vitally important that the\r\n");
- cprintf (
- "system files NET$PASS.SYS and NET$GRP.SYS in SYS:SUPER be saved. These files\r\n");
- cprintf (
- "completely define the identity of all users and groups on this file server.\r\n");
- cprintf (
- "These files will be archived automatically when this archive session commences.\r\n");
- cprintf (
- " Every directory archived during this session will have its rights and\r\n");
- cprintf (
- "list of trustees saved for use in a full system restore.\r\n\r\n");
- cprintf (
- " You MUST login as the real SUPERVISOR user in order to guarantee that a\r\n");
- cprintf (
- "complete system backup will be made. If you are not logged in as SUPERVISOR,\r\n");
- cprintf (
- "press ^C at the next question to exit.\r\n");
-
- savestate = TRUE;
- saverights = TRUE;
- dontask = TRUE;
- system = TRUE;
- getvollist();
- backupsys();
- return;
- }
- else system = FALSE;
-
- dontask = FALSE;
-
- strcpy(line, l);
- showroot(line);
- }
-
-
- ssquery ()
- {
- if (!yes
- ("Do you want to archive the system's user and group definitions? (Y/N) "))
- savestate = FALSE;
- else savestate = TRUE;
- }
-
-
-
- gvname(volnum)
- unsigned volnum;
- {
- int ccode;
-
- ccode = VolStat(volnum, &volinfo2);
- if (ccode == 0 && volinfo2.vol_name[0] == 0) ccode = -1;
- if (ccode) return (ccode);
-
- volinfo2.vol_name[15] = 0;
- return (0);
- }
-
- static char vselect[MAXVOLUMES];
-
- getvollist()
- {
- int vol, count = 0;
-
- for (vol = 0; vol < MAXVOLUMES; vol++) {
- if (gvname(vol) == 0) {
- count++;
- if (choosevol()) vselect[vol] = vol;
- else vselect[vol] = 0xFF;
- }
- else vselect[vol] = 0xFF;
- }
-
- if (!count) {
- error("No system volumes on-line.\7");
- myexit(0);
- }
- }
-
- choosevol()
- {
- char question[80];
-
- if (volinfo2.remove) sprintf(question,
- "Backup removable volume %s? (Y/N) ", volinfo2.vol_name);
- else sprintf(question,
- "Backup fixed volume %s? (Y/N) ", volinfo2.vol_name);
- return (yes(question));
- }
-
- backupsys()
- {
- int vol;
- char volume[20];
-
- for (vol = 0; vol < MAXVOLUMES; vol++) {
- if (vselect[vol] != 0xFF) {
- if (gvname(vol) == 0) { /* make sure vol on-line */
- sprintf(volume, "%s:", volinfo2.vol_name);
- if (!setpath(VARPATH, volume)) {
- if (startup) {
- setup();
- startup = FALSE;
- configlog();
- tapesetup();
- if (savestate) ssave ();
- }
-
- /* BACKUP UP THIS ROOT */
- backupdir();
-
- /* now do the subdirectories */
- showsub (1);
- }
- else cprintf ("\7Error accessing volume %s -- skipping volume.\r\n", volume);
- }
- }
- }
- }
-
-
- ssave ()
- {
- ExFCB search, file;
- ExDirFCB *dfile;
- int ccode, i;
- char savestring [260], f[16];
-
- getcurpath (VARPATH, savestring);
-
- strcpy (pathstring, "SYS:SUPER");
-
- if (!setpath (VARPATH, pathstring)) {
- if (!checkrights (VARPATH, privmask)) {
- if (printlog) printstr ("\r\n");
- lprint ("SYS:SUPER\r\n No backup privileges.\r\n");
- return;
- }
- /* SEARCH FOR NET$PASS.SYS */
- setmem (&search, sizeof (ExFCB), 0);
- movmem ("NET$????SYS", search.fname, 11);
- search.drive = VARPATH + 1;
- search.exset = 0xFF;
- search.flags = 0x02 | 0x04;
- dfile = (ExDirFCB *) &file;
- setDTA (&dfile->exset);
-
- ccode = search1 (&search.exset);
- lprint ("\r\nSYS:SUPER\r\n");
- if (ccode) {
- lprint ("WARNING: Files NET$PASS.SYS and/or NET$GRP.SYS not found!\r\n");
- return;
- }
-
- setmem (list, LISTSIZE*2, 0);
- listcount = 0;
-
- while (ccode == 0) {
- movmem (dfile->fname, f, 11);
- f[11] = 0;
- if (!strcmp("NET$PASSSYS",f) ||
- !strcmp("NET$GRP SYS",f)) addtolist (dfile);
- setDTA (&dfile->exset);
- ccode = searchn (&search.exset);
- }
- if (listcount != 2) {
- lprint ("WARNING: Files NET$PASS.SYS and/or NET$GRP.SYS not found!\r\n");
- for (i = 0; i < listcount; i++) {
- free (list [i]);
- }
- goto klugedone;
- }
-
- AddTrustFile ();
- writelist ();
- }
- klugedone:
- setpath (VARPATH, savestring);
- }